﻿#include "sysmemmonitor.h"
#include "systemmonitormanager.h"
#include "syscfg.h"
#include "common.h"

SysMEMMonitor::SysMEMMonitor(SystemMonitorManager * manager):manager(manager)
{

}

int SysMEMMonitor::start()
{
   bool isFirstTime = true;

    while(state == RunableStateStarted)
    {
        MEMORYSTATUSEX memStatus = getWin_MemStatus();
        manager->updateCurrentMemUsage(memStatus);

        int interval = MEM_CHECK_INTERVAL_SECONDS;


        for(int i = 0; i < interval*5; i ++)
        {
            if(state == RunableStateStarted)
            {
                Sleep(200);
                if(isFirstTime)
                {
                    isFirstTime = false;
                    break;
                }
            }
            else
            {
                break;
            }
        }
    }

    return f_success;
}
